package com.inhim.pjhim.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.inhim.pjhim.R;
import com.inhim.pjhim.utils.GlideCircleUtils;

public class AuthorWidget extends FrameLayout {
    private ImageView ivPhoto;
    private TextView tv_author_name;
    private TextView tv_area;
    private TextView tv_content;
    private TextView tvTitle;

    public AuthorWidget(@NonNull Context context) {
        this(context,null);
    }

    public AuthorWidget(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public AuthorWidget(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        View rootView = inflate(getContext(), R.layout.widget_author,this);
        ivPhoto = rootView.findViewById(R.id.ivPhoto);
        tv_author_name = rootView.findViewById(R.id.tv_author_name);
        tv_area = rootView.findViewById(R.id.tv_area);
        tv_content = rootView.findViewById(R.id.tv_content);
        tvTitle = rootView.findViewById(R.id.tvTitle);
        tvTitle.setVisibility(GONE);
    }

    public void setData(String photoUrl,String name,String area,String content){
        Glide.with(getContext()).load(photoUrl)
                .transform(new GlideCircleUtils.GlideCircleTransform(getContext()))
                .into(ivPhoto);
        tv_author_name.setText(name);
        tvTitle.setVisibility(VISIBLE);
        if (!TextUtils.isEmpty(area)) {
            tv_area.setText("地区：" + area);
            tv_area.setVisibility(VISIBLE);
        }else {
            tv_area.setVisibility(GONE);
        }
        if (!TextUtils.isEmpty(content)) {
            tv_content.setText("简介：" + content);
            tv_content.setVisibility(VISIBLE);
        }else {
            tv_content.setVisibility(GONE);
        }
    }
}
